package com.teemor.demo.juc;

import java.util.concurrent.*;

/**
 * @author zhoulk
 * @Description:
 * @date: 2020/5/8
 */
public class ThreadPoolTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 15, 100000, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(), new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                return new Thread("");
            }
        });
        for (int i = 0; i < 1000; i++) {
            final int index = i;
            executor.submit(() -> {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(index + "-" + Thread.currentThread().getId());
            });
        }

//        executor.execute(() -> {});
        for (int i = 1000; i < 2000; i++) {
            final int index = i;
            FutureTask<?> submit = new FutureTask<>(() -> index);
            executor.submit(submit);
            System.out.println(submit.get());
        }
        Executors.newFixedThreadPool(10);
        Executors.newSingleThreadExecutor();

    }


}
